ESC-POS 指令集:

广泛应用在票据打印机上。SDK 中大约有200条生成指令的函数。

相关类:

类名所在位置功能
PTCommandESCPrinterCommand.framewokESC 基础指令
PTDispatcherPrinterDispatch.framework与打印机通讯
PTFunctionESCDemo对基础指令封装形成功能
PTTestESCDemo测试基础指令或封装后的功能

一个典型的 ESC-POS 指令生成流程如下:

1
/**
2
 *  打印条形码
3
 *
4
 *  @param justification    page 165. 对齐方式       取值0,1,2 : 左、中、右
5
 *  @param type             page 339. 取值:(A:0~6),(B:65~73)
6
 *  @param width            page 355. 取值:(2~6),(68~76)
7
 *  @param height           page 337. 取值:(1~255)
8
 *  @param hri_position     page 332. 取值:(0~3),(48~51)
9
 *  @param barcode          page 339.
10
 *
11
 *  @return 生成的条形码十六进制数据
12
 */
13
- (NSData *)escPrintBarCodeWithJustification:(int)justification
14
                                        Type:(int)type
15
                                       Width:(int)width
16
                                      Height:(int)height
17
                                 HRIPosition:(int)hri_position
18
                                     Barcode:(NSString *)barcode
19
{
20
    //以此为例,演示如何对 ESC-POS基础指令封装,形成功能
21
    PTCommandESC *escCommand = [[PTCommandESC alloc] init]; //创建对象
22
​
23
    [escCommand initCMDQueue];  //初始化存放指令的数组
24
​
25
    /**
26
     *  生成具体的指令,一般包括但不限定:对齐方式,打印起点,打印范围,二维码和图片宽度和高度等等。
27
     *  每一条指令都会加入指令数组中去。
28
     */
29
    [escCommand escSelectJustification:justification];
30
    [escCommand escSelectPrintPositionOfHRICharacers:hri_position];
31
    [escCommand escSetBarCodeWidth:width];
32
    [escCommand escSetBarCodeHeight:height];
33
    [escCommand escPrintBarCodeWithType:type Barcode:barcode];
34
​
35
    return [escCommand generateCMDData];    //从指令数组中取出命令,可以直接通过蓝牙或者 WiFi 发送出去,就可以打印一条二维码
36
}